package repertory.android.ericchen.androidrepertory.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import repertory.android.ericchen.androidrepertory.R;
import repertory.android.ericchen.androidrepertory.view.MyFlowLayout;

/**
 * className:
 * author: Ericchen
 * description:
 * date: 2017/3/9 16:54
 * update: 2017/3/9
 * version:
 */
public class FlowViewActivity extends Activity{
    private MyFlowLayout flowLayout;
    private String[] mLabels = {"歌手 第二期","鹿晗 Venture","奥斯卡电影配乐","爱乐之城","Seve", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "堀北真希", "三生三世","周杰伦","我在人民广场吃炸鸡"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flow_view);
        flowLayout =(MyFlowLayout)findViewById(R.id.flowLayout);
        initLabel();
    }
    // 初始化标签
    private void initLabel() {
        ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(8, 10, 8, 10);// 设置边距
        for (int i = 0; i < mLabels.length; i++) {
            final TextView textView = new TextView(FlowViewActivity.this);
            textView.setTag(i);
            textView.setTextSize(15);
            textView.setText(mLabels[i]);
            textView.setPadding(20, 20, 20, 20);
            textView.setTextColor(Color.BLACK);
            textView.setBackgroundResource(R.drawable.item_flow_view_bg_normal);
            flowLayout.addView(textView, layoutParams);
            // 标签点击事件
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getApplicationContext(), mLabels[(int) textView.getTag()], Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
}
